package trace

import (
	"os"
	"strconv"
)

type TraceConf struct {
	ServiceName string  `json:",default=arpc"`
	Endpoint    string  `json:",optional"`
	Sampler     float64 `json:",default=1.0"`
}

func (c *TraceConf) ReplaceEnv() {
	// ServiceName
	serviceName := os.Getenv("ServiceName")
	if serviceName != "" {
		c.ServiceName = serviceName
	}

	// Endpoint
	endpoint := os.Getenv("Endpoint")
	if endpoint != "" {
		c.Endpoint = endpoint
	}

	// Sampler
	samplerStr := os.Getenv("Sampler")
	if samplerStr != "" {
		if sampler, err := strconv.ParseFloat(samplerStr, 64); err == nil {
			c.Sampler = sampler
		}
	}
}
